﻿Public Partial Class UserGetPassword
    Inherits BaseUserControl

    Public ReadOnly Property RequestedUsername() As String
        Get
            If Request.QueryString("username") IsNot Nothing Then
                Return Request.QueryString("username").ToString
            Else
                Return ""
            End If
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Overrides Sub Rebind()

    End Sub

    Protected Sub btnGetPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPassword.Click

        Try

            If Not Membership.EnablePasswordRetrieval Then
                Me.Prompt("The provider settinge does not allow to retrieve password!", UserControlPromptTypes.Alert)
                Exit Sub
            End If

            Dim membershipUser As MembershipUser = Membership.GetUser(Me.RequestedUsername)
            Dim newPassword As String

            If txtPasswordAnswer.Text.Length = 0 Then
                newPassword = membershipUser.GetPassword
            Else
                newPassword = membershipUser.GetPassword(txtPasswordAnswer.Text)
            End If

            Me.Prompt("Password is: " & newPassword, UserControlPromptTypes.Successful)

        Catch ex As Exception

            Me.RaiseError(ex)

        End Try


    End Sub

End Class